using System;
using System.ComponentModel;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames;
using Microsoft.WowAddonStudio.Tests.Common.Mocks;

using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Tests.Components
{
	[TestFixture]
	public class FrameXmlComponentTest
	{
		#region SetUp

		[SetUp]
		public void SetUp()
		{
		}

		#endregion

		#region TearDown

		[TearDown]
		public void TearDown()
		{
		}

		#endregion

		#region Tests

		[Test(Description = "")]
		public void Test_Default()
		{
			ISite site = new SimpleTestServiceLocator {Name = "TestSite"};

			var component = new FrameXmlComponent<Frame> {Site = site};
			Assert.IsNotNull(component.SerializationObject);
			Assert.IsInstanceOfType(typeof (Frame), component.SerializationObject);
			Assert.AreEqual(site.Name, component.Name);
		}

		[Test(Description = "")]
		[ExpectedException(typeof (ArgumentNullException))]
		public void Test_DefaultFailed()
		{
			new FrameXmlComponent<Frame>(null);
		}

		[Test(Description = "")]
		[ExpectedException(typeof (ArgumentNullException))]
		public void Test_ExpandNameFailedWithNull()
		{
			var component = new FrameXmlComponent<Frame>();
			component.ExpandName((string) null);
		}

		[Test(Description = "")]
		[ExpectedException(typeof (ArgumentNullException))]
		public void Test_ExpandNameFailedWithNullNamedObject()
		{
			var component = new FrameXmlComponent<Frame>();
			component.ExpandName((INamedObject) null);
		}

		[Test(Description = "")]
		[ExpectedException(typeof (ArgumentException))]
		public void Test_ExpandNameFailedWithNullNameOfNamedObject()
		{
			var component = new FrameXmlComponent<Frame>();
			INamedObject namedObject = new Button();
			component.ExpandName(namedObject);
		}

		[Test(Description = "")]
		public void Test_ExpandName()
		{
			ISite site = new SimpleTestServiceLocator {Name = "Parent"};
			var component = new FrameXmlComponent<Frame> {Site = site};

			var name = component.ExpandName("TestName");
			Assert.AreEqual("TestName", name);

			var namedObject = new Button {Name = "Button1"};
			name = component.ExpandName(namedObject);
			Assert.AreEqual("Button1", name);

			name = component.ExpandName("$parentTestName");
			Assert.AreEqual("ParentTestName", name);
		}

		[Test(Description = "")]
		[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "The component is not sited.")]
		public void Test_NotSitedComponent()
		{
			new FrameXmlComponent<Frame> {Name = "TestComponent"};
		}

		#endregion
	}
}